package com.raos.quartz.task;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * first Spring Quartz
 *
 * @author raos
 * @email 991207823@qq.com
 * @date 2021/10/01 20:23
 */
public class FirstSpringJob extends QuartzJobBean {
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    private AnotherBean anotherBean;

    public void setAnotherBean(AnotherBean anotherBean){
        this.anotherBean = anotherBean;
    }

    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        Date date = new Date();
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        logger.info("LOG--FirstSpringJob Executes! {}", sf.format(date));
        System.out.println("FirstSpringJob Executes!" + sf.format(date));
        this.anotherBean.printAnotherMessage();
    }

}
